package com.xiaoq.coms.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UnicodeUtil {
	
	private static Logger logger = LoggerFactory.getLogger(UnicodeUtil.class);
	/**
	 * 将一个字符串中含有中文Unicode编码的转换为中文
	 * 英文不变
	 * @param asciicode
	 * @return
	 */
	public static String ascii2native(String asciicode) {
		if(asciicode!=null){
		String[] asciis = asciicode.split("\\\\u");
		String nativeValue = asciis[0];
		try {
			for (int i = 1; i < asciis.length; i++) {
				String code = asciis[i];
				nativeValue += (char) Integer.parseInt(code.substring(0, 4), 16);
				if (code.length() > 4) {
					nativeValue += code.substring(4, code.length());
				}
			}
		} catch (NumberFormatException e) {
			logger.error("Number类型转换出错！", e);
			return asciicode;
		}
		}else{
			logger.debug("Unicode转换参数为空！");
			return "";
		}
		return asciicode;
		
	}

}
